package com.trinh.utils.crypto;

import com.trinh.utils.crypto.cryptors.*;
import com.trinh.utils.crypto.config.KeyConfig;
import com.trinh.utils.crypto.enu.*;
import com.trinh.utils.crypto.utils.KeyUtil;
import org.omg.CORBA.PRIVATE_MEMBER;

import java.security.KeyPair;

/**
 * @Author: TrinhRae
 * @Package: com.trinh.utils.crypto
 * @Project: generaltools
 * @Date: 2025/6/20 10:57
 */
public class Test {
    private static final String SECRET_KEY = "TJbSpyvupmoP6qAx";
    private static final String IV = "TJbSpyvupmoP6qAx";

    private static final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVUgxeZAw3NxBvBeHtzPrJx6uNBp5G9By1jvbL8Op1oY0qa5B8MsEhkd2BiSqqBKoYERn+ShiJ3xkXFQrH/v1fteiMEMpB0cKHt3ju1mADVORfy7q3KhOheNDbMq/t+aVNUiNE0vYCEzglbxmo0d2gaBlEmLQlCVt4WXauDP9feQIDAQAB";
    private static final String PRIVATE_KEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBANVSDF5kDDc3EG8F4e3M+snHq40Gnkb0HLWO9svw6nWhjSprkHwywSGR3YGJKqoEqhgRGf5KGInfGRcVCsf+/V+16IwQykHRwoe3eO7WYANU5F/LurcqE6F40Nsyr+35pU1SI0TS9gITOCVvGajR3aBoGUSYtCUJW3hZdq4M/195AgMBAAECgYEAoBrotZ+Zm4d0ih98JqMGR5PZKguhl9d4BLy8duzmzEroTMJWuyDM24lDGwn8P4coss+DFtw99py/lBdy9BBp0aCmItmVCGofwUXapiuSBYt1G34nnt9H3ytEOfRUoD6LJqO1G/DHXnc6ZiIpBcygPgsKQeif7x0VDJRcsoS7jlECQQD4Kwf/r6z6S/drk+9GrfgfZQoTkfrIt0fm+XkivxomeC7m4hUFKEeZXeduP1By8ZDUMLNLruYCtrSXEAQUaM3fAkEA3A17EypZ46QN54frpc2kjBuPKQoWF1aSDbugTjG25GAIoNzNwwCsmP3q1QkFAbAnQG0nLRNyC7jtw091JetNpwJAfZq5961grWZZmfdL+cf/d1RaX0FZXtF08PB/YRi8EZBunKj83plec79VbTVacHLXTK5BcSLag7EZggO3LOVGnQJBAJV8zvQpHCGJ7CwyaMIdHkBT5IAjqvg1xkhwAqm8GhuwpYvqFBn51kakkCgi1XTdHv0kaa20fRA7k8HPs6yL2hcCQQD31M1hcAcd5mh00byDuPOGb2PAD2WTDruz+lQt2ywkqAdkuqk99mGsQlqk44Hv0e3oaNVTWOv+sGR5apaDdxFu";

    private static final KeyConfig keyConfigSym = new KeyConfig()
            .setSecretKey(SECRET_KEY)
            .setIv(IV);
    private static final KeyConfig keyConfigAsy = new KeyConfig()
            .setPublicKey(PUBLIC_KEY)
            .setPrivateKey(PRIVATE_KEY);

    private static final String PUBLIC_KEY_SM2 = "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAExOptWfRa4Vq6QU5yt8Nsu+RLtdBLcgssoJPqXTXgHTDGleXfO+924KTiuBvl+oEsEJW1/UGDEOWold7z8u6ymA==";
    private static final String PRIVATE_KEY_SM2 = "MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgil/JNpioDS16zUvUekOIJYdNlg1APgQNDfzpB1sZ+qWgCgYIKoEcz1UBgi2hRANCAATE6m1Z9FrhWrpBTnK3w2y75Eu10EtyCyygk+pdNeAdMMaV5d8773bgpOK4G+X6gSwQlbX9QYMQ5aiV3vPy7rKY";
    private static final KeyConfig keyConfigSm2 = new KeyConfig().setPublicKey(PUBLIC_KEY_SM2).setPrivateKey(PRIVATE_KEY_SM2);

    private static final AES256Util aesUtil = new AES256Util(keyConfigSym);
    private static final RSAUtil rsaUtil = new RSAUtil(keyConfigAsy);

    private static final SM2Util sm2Util = new SM2Util(keyConfigSm2);
    public static void main(String[] args) throws Exception {
//        String symEncrypt = aesUtil.encrypt("oxcnvoain");
//        System.out.println("对称加密加密后数据：" + symEncrypt);
//        String symDecrypt = aesUtil.decrypt("yTgJlyuX71enCFuYFgkHmw==");
//        System.out.println("对称解密后数据：" + symDecrypt);
//
//        String asyEncrypt = rsaUtil.encrypt("oxcnvoain");
//        System.out.println("非对称加密加密后数据：" + asyEncrypt);
//        String asyDecrypt = rsaUtil.decrypt("cD57Aji2pt1rF/x5oRGhwrRAybWf7tE5lcIIzGt5aHx8cBxWN5Bp9arP202KFPdHNO/UqAU8bT0qaQk1UNkDCmwWfR5Cm/5Wd7QShKwLCw6h1zmA9OYR+NFeJ6R35evbdcX26PZrmXMcOEDtNx9/t/ZOP7abPsNXdao5wuuszPc=");
//        System.out.println("非对称解密后数据：" + asyDecrypt);

        String encryptSm2 = sm2Util.encrypt("xokcnvoianosiknxkcvn");
        System.out.println(encryptSm2);
        String decryptSm2 = sm2Util.decrypt("BJJQKuWBkVtDJ3aT+gpewwrzIo7DPS33rVqnwQvQhUkZ7amSazhsd2mWWUr+CY7mWBHlfXB7FIdHPI5olxj9JvsxPyeTyRGA6VWrrbUA0lH9U/08ONN71dISeJBJ72OlYftFwY5Uzya0WyUM7dtFCjZpga7q");
        System.out.println(decryptSm2);


    }

}
